<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-01 17:23:50
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-11 17:44:46
*/
class ArticleControl extends AuthControl{
	private $model;
	public function __auto(){
		$this->model=K('Article');
	}
	//首页
	function index(){
		$page=new Page($this->model->order('ldf_article.aid DESC')->count(),12);
		$article = $this->model->order('ldf_article.aid DESC')->limit($page->limit())->all();
		// p($article);
		$this->article=$article;
		$this->page=$page->show();
		$this->display();
	}
	//添加
	function add(){
		if(IS_POST){
			// p($_POST);die;
			if($this->model->addArt()){
				$this->success('添加文章成功');
			}else{
				$this->error($this->model->error);
			}
		}else{
			$this->cate=cache('category'); //分配文章类别
			$this->tip=getTipStyle(M('tip')->all()); //分配tid
			$this->display();
		}
	}
	//修改
	function edit(){
		if(IS_POST){
			// p($_FILES);
			// p($_POST);die;
			if($this->model->editArt()){
				$this->success('修改文章成功');
			}else{
				$this->error('修改文章失败');
			}
		}else{
			$aid=Q('aid',0,'intval');
			$data=$this->model->field('*,ldf_article.aid,ldf_article.pic,ldf_article.cid')->find(array('ldf_article.aid'=>$aid));
			// p($data);
			$this->field=$data;
			$this->cate=cache('category'); //分配栏目
			$this->tip=getTipStyle(M('tip')->all()); //分配tid
			$this->display();
		}
	}
	//删除
	function del(){
		$this->model->delArt()?$this->success('删除成功'):$this->error('删除失败');
	}
	//====================标签列表=============================
	function tip(){
		$tip=getTipStyle(M('tip')->all());
		$this->tip=$tip;
		$this->display();
	}
	//添加标签
	function addTip(){
		if(IS_POST){
			if(M('tip')->add($_POST)){
				$this->success('添加成功。。。');
			}else{
				$this->error('添加失败...');
			}
		}else{
			$this->display();
		}
	}
	//修改标签
	function editTip(){
		if(IS_POST){
			if(M('tip')->save($_POST)){
				$this->success('修改成功....',U('tip'));
			}
		}else{
			$tid=Q('tid',0,'intval');
			$this->field=M('tip')->find($tid);
			$this->display();
		}
	}
	//修改标签名称ajax
	function ajaxSaveTipName(){
		$tid=Q('tid',0,'intval');
		$tname=Q('tname');
		$tid = M('tip')->save(array('tname'=>$tname,'tid'=>$tid));
		echo $tid?1:0;die;
	}
	//删除标签
	function delTip(){
		$tid=Q('tid',0);
		if(!$tid) $this->error('没有选中项');
		if(M('tip')->del($tid)){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}
	//====更新缓存=====
	function updateCache(){}
}
